package com.babel.util.ciphers;

import java.util.Collection;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.Assert;

public final class AssertUtils {
	public static void assertNull(Object target, String message) {
		if (target != null)
			throw new AssertionException(message);
	}

	public static void assertNotNull(Object target, String message) {
		if (target == null)
			throw new AssertionException(message);
	}

	public static void assertTrue(boolean target, String message) {
		if (!target)
			throw new AssertionException(message);
	}

	public static void assertFalse(boolean target, String message) {
		assertTrue(!target, message);
	}

	public static void assertHasText(String target, String message) {
		if (StringUtils.isEmpty(target))
			throw new AssertionException(message);
	}

	public static void assertMatches(String target, Pattern pattern, String message) {
		if (!pattern.matcher(target).matches())
			throw new AssertionException(message);
	}

	public static void assertHasLength(Collection<?> target, int specifiedLength, String message) {
		Assert.notEmpty(target, message);
		if (target.size() < specifiedLength)
			throw new AssertionException(message);
	}

	public static class AssertionException extends RuntimeException {
		private static final long serialVersionUID = -1023297548643274521L;

		public AssertionException(String message) {
			super(message);
		}
	}

	private AssertUtils() {
	}
}
